package com.cws4cloud.cws.common.mybatis.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.cws4cloud.cws.common.security.util.SecurityUtils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @ClassName: MateMetaObjectHandler
 * @Description:
 * @Author zhlj
 * @Company:digitalchina
 * @Date 2021/1/21 10:29
 */
@Slf4j
@Component
public class MateMetaObjectHandler implements MetaObjectHandler {
	@Override
	public void insertFill(MetaObject metaObject) {
		log.info("start insert fill ....");
		this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
		this.strictInsertFill(metaObject, "createDate", LocalDateTime.class, LocalDateTime.now());
		this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
		this.strictInsertFill(metaObject, "createUser", Integer.class, SecurityUtils.getUserId());
		this.strictInsertFill(metaObject, "updateUser", Integer.class, SecurityUtils.getUserId());
		this.strictInsertFill(metaObject, "adminId", Integer.class, SecurityUtils.getUserId());
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		log.info("start update fill ....");
		this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
		this.strictUpdateFill(metaObject, "updateUser", Integer.class, SecurityUtils.getUserId());
	}
}
